package com.weeho.dongyong.utils;

import com.weeho.dongyong.constant.ConstantInterface;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/13.
 */
@Component
public class LearnCloudUtils {

    private static String CONTENTYPE = "application/json";

    /**
     * learnCloud的post请求
     *
     * @param url
     * @param body
     * @return
     */
    public static byte[] learnCloudHttpsPOST(String url, String body) throws Exception{
        Map map = new HashMap<>();
        map.put("X-LC-Id", ConstantInterface.LEANCLOUD_APP_ID);
        map.put("X-LC-Key", ConstantInterface.LEANCLOUD_MASTER_KEY);
        map.put("Content-Type", CONTENTYPE);

        return HttpsUtil.post0(String.format(url), body, "utf-8", map);

    }

    /**
     * learnCloud的get请求
     *
     * @param url
     * @return
     */
    public static byte[] learnCloudHttpsGET(String url) throws Exception{
        Map map = new HashMap<>();
        map.put("X-LC-Id", ConstantInterface.LEANCLOUD_APP_ID);
        map.put("X-LC-Key", ConstantInterface.LEANCLOUD_APP_KEY);
        map.put("Content-Type", CONTENTYPE);
        return  HttpsUtil.get0(url, "utf-8", map);
    }

    public static class RTM {
        /**
         * 系统对话给用户发消息
         *
         * @param body
         * @return
         */
        public static byte[] rtmMessages(String body) throws Exception{
            String url = "https://leancloud.cn/1.1/rtm/messages";
            return learnCloudHttpsPOST(url, body);
        }

    }
}
